/*   1:    */ package gov.sat.tax.fwsk.wlrz;
/*   2:    */ 
/*   3:    */ /*   7:    */ import java.math.BigInteger;

import com.htxx.security.cipher.CommonBean;
/*   4:    */ import com.htxx.security.cipher.DESCipher;
/*   5:    */ import com.htxx.security.cipher.RSACipher;
/*   6:    */ 
/*   8:    */ 
/*   9:    */ public class CryptographerBean
/*  10:    */ {
/*  11:    */   public byte[] RealTmDecrypt(String entry)
/*  12:    */   {
/*  13: 20 */     String corpID = "";
/*  14:    */     
/*  15: 22 */     BigInteger modb = new BigInteger("3321292177881268720699107136875462713789");
/*  16: 23 */     BigInteger exp = new BigInteger("5");
/*  17:    */     
/*  18: 25 */     RSACipher rsa = null;
/*  19: 26 */     DESCipher des = null;
/*  20:    */     
/*  21: 28 */     int i = 0;int j = 0;int fsize = 0;int kl = 0;int dl = 0;int al = 0;int l = 0;
/*  22: 29 */     byte[] fBuffer = new byte[512];
/*  23: 30 */     byte[] keyLen = new byte[2];
/*  24: 31 */     byte[] dataLen = new byte[4];
/*  25: 32 */     byte[] keyCipher = (byte[])null;
/*  26: 33 */     byte[] keyFormer = new byte[8];
/*  27: 34 */     byte[] keyTemp = (byte[])null;
/*  28: 35 */     byte[] dataCipher = new byte[8];
/*  29: 36 */     byte[] dataFormer = new byte[8];
/*  30: 37 */     byte[] data = (byte[])null;
/*  31:    */     try
/*  32:    */     {
/*  33: 41 */       CommonBean cn = new CommonBean();
/*  34: 42 */       fBuffer = CommonBean.hex2byte(entry);
/*  35:    */       
/*  36: 44 */       fsize = fBuffer.length;
/*  37: 45 */       System.out.println(fsize);
/*  38: 46 */       if (fsize > 0)
/*  39:    */       {
/*  40: 49 */         for (i = 0; i < 4; i++) {
/*  41: 51 */           dataLen[i] = fBuffer[(5 - i)];
/*  42:    */         }
/*  43: 53 */         dl = Integer.valueOf(CommonBean.byte2hex(dataLen), 16).intValue();
/*  44: 56 */         for (i = 0; i < 2; i++) {
/*  45: 58 */           keyLen[i] = fBuffer[(7 - i)];
/*  46:    */         }
/*  47: 60 */         kl = Integer.valueOf(CommonBean.byte2hex(keyLen), 16).intValue();
/*  48: 63 */         for (i = 0; i < 4; i++) {
/*  49: 65 */           dataLen[i] = fBuffer[(11 - i)];
/*  50:    */         }
/*  51: 67 */         al = Integer.valueOf(CommonBean.byte2hex(dataLen), 16).intValue();
/*  52: 70 */         if ((dl != fsize) || (dl - 24 - kl != 8 * ((dl - 24 - kl) / 8))) {
/*  53: 71 */           throw new Exception("纳税人识别号" + corpID + ": 提交的待认证实时文件数据校验未通过!");
/*  54:    */         }
/*  55:    */       }
/*  56:    */       else
/*  57:    */       {
/*  58: 74 */         throw new Exception("纳税人识别号" + corpID + ": 提交的待认证实时文件长度为0!");
/*  59:    */       }
/*  60: 77 */       keyCipher = new byte[kl];
/*  61: 78 */       for (i = 0; i < kl; i++) {
/*  62: 79 */         keyCipher[i] = fBuffer[(24 + i)];
/*  63:    */       }
/*  64: 81 */       rsa = new RSACipher();
/*  65: 82 */       rsa.setN(modb);
/*  66: 83 */       rsa.setE(exp);
/*  67: 84 */       keyTemp = rsa.Encrypt(keyCipher);
/*  68: 86 */       for (i = 0; i < 8; i++) {
/*  69: 87 */         keyFormer[i] = 0;
/*  70:    */       }
/*  71: 89 */       if (keyTemp.length == 8)
/*  72:    */       {
/*  73: 90 */         keyFormer = keyTemp;
/*  74:    */       }
/*  75: 91 */       else if (keyTemp.length < 8)
/*  76:    */       {
/*  77: 93 */         l = 8 - keyTemp.length;
/*  78: 94 */         for (i = 0; i < keyTemp.length; i++) {
/*  79: 95 */           keyFormer[(i + l)] = keyTemp[i];
/*  80:    */         }
/*  81:    */       }
/*  82: 97 */       else if (keyTemp.length > 8)
/*  83:    */       {
/*  84: 99 */         throw new Exception("纳税人识别号" + corpID + ": " + "实时解密后的DES密钥长度超界!");
/*  85:    */       }
/*  86:102 */       dl = dl - 24 - kl;
/*  87:103 */       data = new byte[al];
/*  88:104 */       des = new DESCipher(keyFormer);
/*  89:105 */       for (i = 0; i < dl; i += 8)
/*  90:    */       {
/*  91:107 */         for (j = 0; j < 8; j++)
/*  92:    */         {
/*  93:109 */           dataCipher[j] = 0;
/*  94:110 */           dataFormer[j] = 0;
/*  95:    */           
/*  96:112 */           dataCipher[j] = fBuffer[(24 + kl + i + j)];
/*  97:    */         }
/*  98:114 */         des.decrypt(dataCipher, 0, dataFormer, 0);
/*  99:115 */         if ((dl != al) && (dl == i + 8)) {
/* 100:117 */           l = 8 - (dl - al);
/* 101:    */         } else {
/* 102:121 */           l = 8;
/* 103:    */         }
/* 104:123 */         for (j = 0; j < l; j++) {
/* 105:125 */           data[(i + j)] = dataFormer[j];
/* 106:    */         }
/* 107:    */       }
/* 108:    */     }
/* 109:    */     catch (Exception e)
/* 110:    */     {
/* 111:131 */       System.out.println("[ERROR] RealTmDecrypt" + e.toString());
/* 112:132 */       data = (byte[])null;
/* 113:    */     }
/* 114:    */     finally {}
/* 115:138 */     String val = data.toString();
/* 116:139 */     return data;
/* 117:    */   }
/* 118:    */ }


/* Location:           D:\htjs\document\wsrz\WsrzEjbInf\
 * Qualified Name:     gov.sat.tax.fwsk.wlrz.CryptographerBean
 * JD-Core Version:    0.7.0.1
 */